function [bingrid, shape] = improcess_m(img)
%IMROCESS Processes the image to prepare it for an HMM

% Number of segments
NSEGR = 3;
NSEGC = 3;
% Size of the grids
NRGRIDCELL = 3;
NCGRIDCELL = 3;
% Number of grids
NRWHOLEGRID = NSEGR*NRGRIDCELL;
NCWHOLEGRID = NSEGC*NCGRIDCELL;

shape = imresize(img, [NRWHOLEGRID NCWHOLEGRID]);

bingrid = zeros( NSEGR, NSEGC );

for i = 1 : NRWHOLEGRID
    binI = floor((i-1)/NRGRIDCELL)+1;
    for j = 1 : NCWHOLEGRID
        binJ = floor((j-1)/NCGRIDCELL)+1;
        bingrid(binI, binJ) = bingrid(binI, binJ) + shape(i,j);
    end
end

bingrid = bingrid(:)' + 1;